package com.telit.common.service;

import com.telit.common.config.GaodeProperties;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;


/**
 * @Auther zhouyu
 * @description 高德地图
 **/
@Service
public class GaodeService {


    private String key;

    public GaodeService(GaodeProperties gaodeProperties){
        key=gaodeProperties.getKey();
    }

    @Autowired
    private RestTemplate restTemplate;

    private static final String REGEO_URL = "https://restapi.amap.com/v3/geocode/regeo";

    /**
     * 根据经纬度查询详细地点
     */
    public String queryAddressByLaAndLo(String longitude,String latitude){
        Map<String,Object> paramsMap = new HashMap<>(6);
        paramsMap.put("key",key);
        paramsMap.put("output","JSON");
        paramsMap.put("location",longitude+","+latitude);
        String detailAddress = restTemplate.getForObject(REGEO_URL + "?location={location}&output={output}&key={key}", String.class, paramsMap);
        return detailAddress;
    }
}
